<script>
	import Routine from './libs/routine.js';
	import { detectMembershipExpiration } from './api/user.js';
	import {
		mapGetters
	} from "vuex";
	export default {
		computed: {
			...mapGetters({
				isLogin: 'isLogin',
				uid: 'uid',
				userType: 'userType'
			})
		},
		onLaunch: function() {
			let that = this;
			console.log('App Launch');
			//如果是登录，并且身份是门店,检查会员是否过期
			if (that.isLogin){
				if (that.userType === "STORE"){
					detectMembershipExpiration({
						userInfoId: that.uid
					}).then(res =>{
						if (res.value){
							that.$store.commit("USER_TYPE", "CAR");
						}
					})
				}
			}

			// wx.showModal({
			// 	title: '会员政策调整',
			// 	content: '亲爱的用户，由于政策调整，即日起，会员门店服务将开始收费。请在[我的] -> [我的会员] 开通即可',
			// 	showCancel: false,
			// 	confirmText: '我知道了',
			// 	success: function(res) {
			// 		if (res.confirm) {

			// 		}
			// 	}
			// });

			// #ifdef MP

			const updateManager = wx.getUpdateManager();
			const startParamObj = wx.getEnterOptionsSync();
			if (wx.canIUse('getUpdateManager') && startParamObj.scene != 1154) {
				const updateManager = wx.getUpdateManager()
				console.log(updateManager);
				updateManager.onCheckForUpdate(function(res) {
					// 请求完新版本信息的回调
					// console.log(res.hasUpdate)
					if (res.hasUpdate) {
						updateManager.onUpdateFailed(function() {
							return that.Tips({
								title: '新版本下载失败'
							});
						});
						updateManager.onUpdateReady(function() {
							wx.showModal({
								title: '更新提示',
								content: '新版本已经下载好，是否重启当前应用？',
								success(res) {
									if (res.confirm) {
										that.$store.commit("LOGOUT");
										updateManager.applyUpdate();
									} else if (res.cancel) {
										that.$store.commit("LOGOUT");
									}
								}
							})
						})
						updateManager.onUpdateFailed(function() {
							wx.showModal({
								title: '发现新版本',
								content: '请删除当前小程序，重启搜索打开...',
							})
						})
					}
				})
			}
			// #endif
			// #ifdef MP
			let menuButtonInfo = uni.getMenuButtonBoundingClientRect();
			that.globalData.navH = menuButtonInfo.top * 2 + menuButtonInfo.height / 2;
			const version = uni.getSystemInfoSync().SDKVersion
			if (Routine.compareVersion(version, '2.21.3') >= 0) {
				console.log(version)
				that.$Cache.set('MP_VERSION_ISNEW', true)
			} else {
				that.$Cache.set('MP_VERSION_ISNEW', false)
			}
			// #endif

			// 如果是批发商就先隐藏产品tabber
			// #ifdef MP
			uni.setTabBarItem({
				index: 2,
				visible: false
			})
			// #endif
		},
		onShow: function() {
			console.log('App Show')
		},
		onHide: function() {
			console.log('App Hide')
		}
	}
</script>

<style lang="scss">
	/*每个页面公共css */
	@import '@/static/css/uni.css';
	@import '@/static/css/base.css';
	@import "@/uni_modules/uview-ui/index.scss";
	@import 'static/iconfont/iconfont.css';
</style>